@directive dynamic roles;
@var isAdd = shiro.hasPermission("sys.user.add");
@var isEdit = shiro.hasPermission("sys.user.edit");
@var isDel = shiro.hasPermission("sys.user.delete");
@var isUserRoles = shiro.hasPermission("sys.userRoles.edit");
@var content = {
<div class="panel panel-success">
    <div class="panel-body">
        <div id="userTable"></div>
        <script type="text/javascript">
            var rolesOld = JSON.parse('${roles}');
            var roles = [{value: '', name: '-- 请选择角色 --'}];
            rolesOld.forEach(function (item) {
                roles.push({value: item.id, name: '-- ' + item.name + ' --'});
            });
            var setting = {
                dataUrl: '/sys/user/list',//数据加载地址
                addUrl: '/sys/user/add',//添加地址
                editUrl: '/sys/user/edit',//菜单编辑地址
                delUrl: '/sys/user/delete',//删除数据地址
                isAddBtnIsShow: '${isAdd}' === 'true',
                addBtnText: '添加',
                isEditBtnIsShow: '${isEdit}' === 'true',
                editBtnText: '编辑',
                isDeleteBtnIsShow: '${isDel}' === 'true',
                deleteBtnText: '删除',
                toolbar: 'userToolbar',
                columns: [{checkbox: true},
                    {
                        field: 'name',
                        title: '用户名',
                        align: 'center',
                        formatter: function (arg, obj) {
                            if ('${isEdit}' === 'true') {
                                return '<a href="javascript:void(0);" onclick="table.bootstrapTableExtension(\'edit\',\'' + setting.editUrl + '/' + obj.id + '\');">' + arg + '</a>';
                            } else {
                                return arg;
                            }
                        }
                    },
                    {field: 'nick', title: '昵称', align: 'center', filterControl: 'input'},
                    {field: 'email', title: '电子邮件', align: 'center', filterControl: 'input'},
                    {
                        field: 'birthday',
                        title: '出生日期',
                        align: 'center',
                        sortable: true,
                        formatter: function (arg) {
                            return arg.slice(0, 10);
                        }
                    },
                    {field: 'address', title: '地址', align: 'center', visible: false},
                    {
                        field: 'createTime', title: '创建时间', align: 'center', sortable: true,
                        formatter: function (arg) {
                            return arg.slice(0, 10) + " " + arg.slice(11, 20);
                        }
                    },
                    {
                        field: 'updateTime', title: '修改时间', align: 'center', sortable: true,
                        formatter: function (arg) {
                            return arg.slice(0, 10) + " " + arg.slice(11, 20);
                        }
                    },
                    {field: 'roleName', title: '主角色', align: 'center', sortable: true},
                    {
                        field: 'deleteTime',
                        title: '删除时间（如果已删除）',
                        align: 'center',
                        visible: false,
                        formatter: function (arg) {
                            if (arg == null) {
                                return arg;
                            }
                            return arg.slice(0, 10) + " " + arg.slice(11, 20);
                        }
                    }
                ],
                otherSelects: [
                    {
                        isShow: true,
                        classes: 'form-control',
                        name: 'roleId',
                        id: 'roleId',
                        data: roles
                    }
                ],
                //其它的按钮
                otherButtons: [
                    {
                        isShow: 'true' === '${isUserRoles}',
                        classes: 'btn btn-info',
                        iconClasses: 'glyphicon glyphicon-record',
                        text: '额外角色',
                        id: 'btn-user-roles',
                        btnEvent: function () {
                            var obj = table.bootstrapTable('getSelections');
                            if (obj.length !== 1) {
                                layer.msg('请选择一条数据', {icon: 5});
                                return false;
                            }
                            table.bootstrapTableExtension('newLayer', {
                                url: '/sys/userRoles/edit/' + obj[0].id,
                                title: '用户【' + obj[0].name + '】的额外角色'
                            });
                        }
                    }
                ]

            };
            var table = $('#userTable').bootstrapTableExtension(setting);
        </script>
    </div>
</div>
@};
@layout('../../layout/_open_content.html',{content:content}){}